use logos::Logos;

#[derive(Logos, Debug, PartialEq)]
#[logos(skip  r"[ \t]+")]
pub enum ExprToken {
    #[regex(r"((\d*\.\d+)|(\d+\.?))", |input| input.slice().parse::<f64>().expect("not a number"))]
    Number(f64), // prefix
    #[regex(r"<[^>]*>", |input| input.slice().to_string())]
    Chemical(String), // prefix
    #[token("+")]
    Add,
    #[token("-")]
    Sub,
    #[token("*")]
    Mul,
    #[token("/")]
    Div,
    #[regex(r"[({\[]")]
    Lparent, // prefix
    #[regex(r"[)}\]]")]
    Rparent,
}

#[derive(Logos, Debug, PartialEq, Copy, Clone)]
pub enum ChemToken {
    #[regex(r"((\d*\.\d+)|(\d+\.?))", |input| input.slice().parse::<f64>().expect("not a number"))]
    Number(f64),
    #[regex(r"[A-Z][a-z]?", |input| {
        let elem_string = input.slice().to_string();
        (elem_string.chars().nth(0).unwrap_or(' '), elem_string.chars().nth(1).unwrap_or(' '))
    })]
    Elem((char, char)),
    #[regex(r"[({\[]")]
    Lparent,
    #[regex(r"[)}\]]")]
    Rparent,
    #[regex(r"[ \t]+")]
    Space,
}
